package top.ztf.erp.visitors;

import top.ztf.erp.dao.PermissionDao;
import top.ztf.erp.dao.RolePermissionRelationDao;
import top.ztf.erp.domain.PermissionNode;


public class CheckVisitorIml extends VisitorTemplate{

    private final RolePermissionRelationDao permissionRelationDao;
    private boolean status = false;

    public CheckVisitorIml(PermissionDao permissionDao, RolePermissionRelationDao permissionRelationDao) {
        super(permissionDao);
        this.permissionRelationDao = permissionRelationDao;
    }

    public boolean getStatus() {
        return status;
    }

    @Override
    public void doCHeckPermissionNode(PermissionNode permissionNode) {
        //检测改节点是否正在被使用
        boolean check = checkPermissionRoleRelation(permissionNode.getId());
        if (check){
            //有被占用
            this.status = true;
            System.out.println(permissionNode.getName()+"--有被占用");
        }else {
            //没有被占用
            System.out.println(permissionNode.getName()+"--没有被占用");
        }
    }

    /**
     * 检查该权限 是否被角色占用
     * @param permissionId 权限菜单的id
     * @return true 被占用 ,false 正常
     */
    public boolean checkPermissionRoleRelation(String permissionId) {
        int count = permissionRelationDao.getRelationByPermissionId(permissionId);
        if (count>0){
            //被占用
            return true;
        }
        return false;
    }




}
